var a = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), e = require("../../../@babel/runtime/helpers/asyncToGenerator"), t = getApp();

Page({
    data: {
        avatar: "",
        level_name: "",
        area_level_name: "",
        nickname: "",
        active: "index",
        tabs: [],
        show_tabs: !1,
        area_list: [],
        area_total_page: 1,
        area_page: 1,
        area_sum: "",
        info: {},
        list: [],
        sum: "",
        total_page: 1,
        page: 1
    },
    onLoad: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        }), this.get_weekly();
    },
    onChange: function(a) {
        var e = a.detail.name;
        this.setData({
            active: e
        }), "index" == e ? this.get_weekly() : this.get_area();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    get_area: function() {
        var a = this, e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 1;
        t._postNetWork({
            url: t.getNetAddresss("plugin.weekly-rewards.frontend.controllers.center.area"),
            data: {
                page: e
            },
            success: function(n) {
                var r = n.data, s = r.result, i = r.data, l = r.msg, o = r.level_name;
                if (s) {
                    var u = [], d = i.info, g = i.sum, c = i.list;
                    c.data && 0 !== c.data.length && (u = 1 == e ? c.data : a.data.area_list.concat(c.data), 
                    a.setData({
                        area_level_name: o,
                        area_list: u,
                        area_sum: g,
                        area_total_page: c.last_page,
                        area_page: c.current_page
                    })), a.setData({
                        show_tabs: !0,
                        avatar: null == d ? void 0 : d.info,
                        nickname: null == d ? void 0 : d.nickname,
                        info: d
                    });
                } else a.setData({
                    show_tabs: !1
                }), t.tips(l);
            }
        });
    },
    get_weekly: function() {
        var n, r = this, s = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 1;
        t._postNetWork({
            url: t.getNetAddresss("plugin.weekly-rewards.frontend.controllers.center.index"),
            data: {
                page: s
            },
            success: (n = e(a.default.mark(function e(n) {
                var i, l, o, u, d, g, c, _, p;
                return a.default.wrap(function(a) {
                    for (;;) switch (a.prev = a.next) {
                      case 0:
                        i = n.data, l = i.result, o = i.data, u = i.msg, d = i.level_name, l ? (g = o.info, 
                        c = o.sum, _ = o.list, p = [], _.data && 0 !== _.data.length && (p = 1 == s ? _.data || [] : r.data.list.concat(_.data), 
                        r.setData({
                            level_name: d,
                            list: p,
                            sum: c,
                            total_page: _.last_page,
                            page: _.current_page
                        })), r.setData({
                            avatar: null == g ? void 0 : g.avatar,
                            nickname: null == g ? void 0 : g.nickname,
                            info: g
                        })) : t.tips(u);

                      case 2:
                      case "end":
                        return a.stop();
                    }
                }, e);
            })), function(a) {
                return n.apply(this, arguments);
            })
        });
    },
    onReachBottom: function() {
        if ("index" == this.data.active) {
            if (this.data.page >= this.data.total_page) return !1;
            var a = this.data.page + 1;
            this.get_weekly(a);
        } else {
            if (this.data.area_page >= this.data.area_total_page) return !1;
            var e = this.data.area_page + 1;
            this.get_area(e);
        }
    },
    onShareAppMessage: function() {}
});